package com.hippy.erya.config.jsonobj;

import com.hippy.erya.common.Constants;
import com.hippy.erya.common.DateUtil;
import com.hippy.erya.enums.ErrorCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@ApiModel(description = "响应JSON")
@Data
public class ResponseJson<T>   implements Serializable {

    @ApiModelProperty(value = "请求业务数据属性--result")
    private ResultResponse<T> result;

    public ResponseJson(){
        this.setResult(new ResultResponse());
    }

    public void success()
    {
        CommonResponse common = new CommonResponse();

        common.setRetFlag(Constants.RetFlag.N);
        common.setRetCode(Constants.ReturnCode.RET_CODE_SUCCESS);
        common.setRetMsg(Constants.ReturnMsg.RET_MSG_SUCCESS);
        common.setRetDateTime(DateUtil.getCurrent());
        result.setCommon(common);

    }

    public void success(String retMsg)
    {
        CommonResponse common = new CommonResponse();

        common.setRetFlag(Constants.RetFlag.N);
        common.setRetCode(Constants.ReturnCode.RET_CODE_SUCCESS);
        common.setRetMsg(retMsg);
        common.setRetDateTime(DateUtil.getCurrent());
        result.setCommon(common);
    }

    public void fail(String retCode, String retMsg)
    {
        CommonResponse common = new CommonResponse();

        common.setRetFlag(Constants.RetFlag.E);
        common.setRetCode(retCode);
        common.setRetMsg(retMsg);
        common.setRetDateTime(DateUtil.getCurrent());
        result.setCommon(common);
    }



    public void printResultToJson(T data)
    {
        result.setData(data);

    }

    public ResponseJson settingValidateFailRetMsg(String retMsg) {
        CommonResponse common = new CommonResponse();

        common.setRetFlag(Constants.RetFlag.E);
        common.setRetCode(ErrorCodeEnum.ERROR_PARAM.getCode());
        common.setRetMsg(retMsg);
        common.setRetDateTime(DateUtil.getCurrent());
        result.setCommon(common);

        return this;
    }


}
